package com.example.picture_sharing_system;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.material.tabs.TabLayout;

import utils.WorksListAdapter;


public class HomeFragment extends Fragment {

    private String username;
    private int userid;

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private String[] titles = {"推荐", "我的"};

    private Fragment[] fragments = {new WorksListFragment(), new MyWorksListFragment()};

    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Intent intent = getActivity().getIntent();

        userid = intent.getIntExtra("userid", -1);
        username = intent.getStringExtra("username");


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        tabLayout = rootView.findViewById(R.id.tl_tab);
        viewPager = rootView.findViewById(R.id.vp_content);

        viewPager.setAdapter(new WorksListAdapter(getChildFragmentManager(), fragments, titles));
        tabLayout.setupWithViewPager(viewPager);

        return rootView;
    }

}